package com.transaction.service.impl;


import com.transaction.dao.OrdDao;
import com.transaction.dao.UserDao;
import com.transaction.domain.ReturnOrder;
import com.transaction.domain.User;
import com.transaction.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private OrdDao ordDao;

    @Override
    public boolean findUserById(User user) {
        User user1=userDao.findUserById(user);
        if (user1!=null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public User findUserInfo(User user) {
        return userDao.findUserInfo(user);
    }

    @Override
    @Transactional
    public boolean userRegister(User user) {
        Integer r=userDao.userRegist(user);
        if (r!=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public User userLogin(User user) {
        return userDao.userLogin(user);
    }


    @Override
    @Transactional
    public boolean userUpdate(User user) {
        Integer r=userDao.updateUser(user);
        System.out.println(r);
        if (r==1){
            return true;
        }else if(r>1){
            throw new RuntimeException("影响多行数据");
        }else {
            return false;
        }
    }

    @Override
    public List<ReturnOrder> findOrderListByUid(String uid) {
        return ordDao.findOrderListByUid(uid);
    }
}
